package com.jingtai.shop.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jingtai.common.template.ResultMapInfo;
import com.jingtai.common.webfacade.BasePageBO;
import com.jingtai.common.webfacade.IdBO;
import com.jingtai.core.entity.shop.Feedback;
import com.jingtai.shop.common.template.ShopBaseController;
import com.jingtai.shop.service.user.FeedbackService;
import com.jingtai.shop.webfacade.bo.feedback.ApplyFeedbackBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


/**
 * @author GR
 */
@Api(tags = "商城-反馈")
@RestController
@RequestMapping("/shop/feedback")
@CrossOrigin(origins = "*")
public class FeedbackController extends ShopBaseController {

    @Resource
    private FeedbackService feedbackService;

    /**
     * 用户申请反馈
     */
    @ApiOperation(value = "用户申请反馈")
    @ApiOperationSupport(ignoreParameters = {"bo.platform", "bo.version"})
    @PostMapping("/userApplyFeedback")
    public Map<String, Object> userApplyFeedback(@RequestBody ApplyFeedbackBO bo) {
        bo.validate();
        boolean userApplyStatus = feedbackService.userApplyFeedback(bo.getApplyContent(), bo.getImages(), getUserId());
        return returnResultMap(userApplyStatus ? ResultMapInfo.SUBMITSUCCESS : ResultMapInfo.SUBMITFAIL);
    }

    /**
     * 分页查询用户反馈内容
     */
    @ApiOperation(value = "分页查询用户反馈内容")
    @ApiOperationSupport(ignoreParameters = {"bo.platform", "bo.version"})
    @PostMapping("/pageFeedback")
    public Map<String, Object> pageFeedback(@RequestBody BasePageBO bo) {
        bo.validate();
        Page<Feedback> feedbackPage = feedbackService.pageFeedback(getUserId(), bo.getPageNo(), bo.getPageSize());
        return returnResultMap(ResultMapInfo.GETSUCCESS, feedbackPage);
    }


    /**
     * 用户查询反馈信息内容
     */
    @ApiOperation(value = "用户查询反馈信息内容")
    @ApiOperationSupport(ignoreParameters = {"bo.platform", "bo.version"})
    @PostMapping("/queryFeedbackDetails")
    public Map<String, Object> queryFeedbackDetails(@RequestBody IdBO bo) {
        bo.validate();
        Feedback feedback = feedbackService.queryFeedbackDetails(bo.getId());
        return returnResultMap(ResultMapInfo.GETSUCCESS, feedback);
    }

    /**
     * 用户撤销反馈信息
     */
    @ApiOperation(value = "用户撤销反馈信息")
    @ApiOperationSupport(ignoreParameters = {"bo.platform", "bo.version"})
    @PostMapping("/revokeFeedback")
    public Map<String, Object> revokeFeedback(@RequestBody IdBO bo) {
        bo.validate();
        boolean revokeStatus = feedbackService.revokeFeedback(bo.getId());
        return returnResultMap(revokeStatus ? ResultMapInfo.OPERATE_SUCCESS : ResultMapInfo.OPERATE_FAIL);
    }
}
